from django.db import models


from note.models import Note
from django.contrib.auth import get_user_model

User = get_user_model()


class HistoryRecord(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="history_records")
    note = models.ForeignKey(Note, on_delete=models.CASCADE, related_name="history_records")
    action = models.CharField(max_length=255)  # 操作的内容，例如 "浏览了笔记"
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.user.username} - {self.action} on {self.note.title} - {self.created_at}"

    class Meta:
        ordering = ['-created_at']  # 按创建时间降序排列